<!-- 详细信息 -->
<template>
  <div>
    <van-form @submit="onSubmit" disabled>
      <van-field v-model="form.name" name="设备名称" label="设备名称" />
      <van-field v-model="form.equipmentNo" name="设备编号" label="设备编号" />
      <van-field v-model="form.areaInfo.name" name="所在区域" label="所在区域" />
      <van-field v-model="form.remark" name="设备描述" label="设备描述" />
      <van-field v-model="form.managerId" name="负责人" label="负责人" />
      <van-field v-model="form.examinerId" name="监察人" label="监察人" />
      <van-field v-model="form.supplierInfo.supplierName" name="供应商" label="供应商" />
      <van-field v-model="form.produceDate" name="生产日期" label="生产日期" />
      <van-field v-model="form.checkMonth" name="检定周期" label="检定周期" />
      <van-field v-model="form.type" name="设备规格" label="设备规格" />
      <van-field v-model="form.boughtFee" name="采购费用" label="采购费用" />
      <van-field v-model="form.depreciateFee" name="折旧费用" label="折旧费用" />
      <van-field v-model="form.insuranceFee" name="保险费用" label="保险费用" />
      <van-field v-model="form.repairFee" name="保修费用" label="保修费用" />
    </van-form>
  </div>
</template>

<script>
import { Field, Form } from 'vant'
import { GetEquipmentInfo, getUser } from '@/api/index'

export default {
  data () {
    return {
      form: {},
      facilityId: ''
    }
  },

  components: {
    [Form.name]: Form,
    [Field.name]: Field
  },
  created () {
    this.getId()
    this.GetEquipmentInfo({ id: this.facilityId })
  },
  computed: {},

  methods: {
    abs (val) {
      // 金额转换 分->元 保留2位小数 并每隔3位用逗号分开 1,234.56
      var str = (val / 100).toFixed(2) + ''
      var intSum = str.substring(0, str.indexOf('.')).replace(/\B(?=(?:\d{3})+$)/g, ',')// 取到整数部分
      var dot = str.substring(str.length, str.indexOf('.'))// 取到小数部分搜索
      var ret = intSum + dot
      return ret
    },
    getId () {
      const { facilityId } = this.$route.query
      this.facilityId = facilityId
    },
    onSubmit () {},
    async getUser (data) {
      const res = await getUser(data)
      return res
    },
    async GetEquipmentInfo (data) {
      const res = await GetEquipmentInfo(data)
      this.form = res
      const manager = await getUser({ idList: res.managerId })
      const examiner = await getUser({ idList: res.examinerId })
      const managerVal = Object.values(manager)
      this.form.managerId = managerVal[0].name
      const examinerVal = Object.values(examiner)
      this.form.examinerId = examinerVal[0].name

      // 分转元
      this.form.boughtFee = this.abs(this.form.boughtFee)
      this.form.depreciateFee = this.abs(this.form.depreciateFee)
      this.form.insuranceFee = this.abs(this.form.insuranceFee)
      this.form.repairFee = this.abs(this.form.repairFee)
    }
  }
}
</script>
<style lang='less' scoped>
</style>
